<template>
  <div>
    <el-card style="min-width: 1200px">
      <el-row>
        <div class="tableSelectWrap">
          <el-form
            ref="orderCenterForm"
            :model="commandForm"
            label-width="100px"
          >
            <el-col :span="6">
              <el-form-item label="交易类型" prop="orderType">
                <el-select
                  v-model="commandForm.orderType"
                  style="width: 100%"
                  placeholder="请选择交易类型"
                >
                  <el-option
                    v-for="(item, idx) of tradeList"
                    :key="idx"
                    :label="item.orderTypeName"
                    :value="item.orderType"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6" :offset="2">
              <el-form-item label="支付状态" prop="status">
                <el-select
                  v-model="commandForm.status"
                  style="width: 100%"
                  placeholder="请选择支付状态"
                >
                  <el-option
                    v-for="item of payStateList"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6" :offset="2">
              <el-button class="width120" @click="resetForm('orderCenterForm')"
                >重置</el-button
              >
              <el-button
                type="primary"
                class="width120"
                @click="
                  () => {
                    this.dataForm = JSON.parse(
                      JSON.stringify(this.commandForm)
                    );
                    this.getDataList();
                  }
                "
                >查询</el-button
              >
            </el-col>
          </el-form>
        </div>
      </el-row>
    </el-card>
    <el-card style="margin-top: 15px; min-width: 1200px">
      <el-table :data="dataList">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="创建时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="orderNo"
          align="center"
          label="云尘付流水号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.innerPayformNo ? scope.row.innerPayformNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="serviceName"
          align="center"
          label="交易类型"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.orderTypeName ? scope.row.orderTypeName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="fmtPayAmount"
          sortable
          align="center"
          label="支付金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.fmtActualAmount ? scope.row.fmtActualAmount : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="payStatus"
          align="center"
          label="支付状态"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
              :class="`${
                scope.row.status == 'fail_pay'
                  ? 'failed'
                  : scope.row.status == 'success_pay'
                  ? 'succeed'
                  : 'pedding'
              } `"
            >
              {{ scope.row.statusName ? scope.row.statusName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="act" width="200" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetails(scope.row)"
              >详情</el-button
            >
            <el-button
              type="text"
              v-if="scope.row.status == 'wait_pay' && scope.row.url != null"
              @click="linkToPayCenter(scope.row.url)"
              >去支付</el-button
            >
            <el-button
            v-if="scope.row.status == 'wait_pay' && scope.row.url != null"
              type="text"
              @click="NoPay(scope.row)"
              >取消订单</el-button
            >
          </template>
        </el-table-column>
        <!-- <el-table-column
          show-overflow-tooltip
          prop="expireDate"
          align="center"
          label="截止日期"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.expireDate ? scope.row.expireDate : "-" }}
            </div>
          </template>
        </el-table-column> -->
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
    <!-- 详情抽屉 -->
    <detail-drawer
      :drawer.sync="drawer"
      :info="detailsInfo"
      :activeKey="activeKey"
    ></detail-drawer>
    <!-- <el-dialog title="查看详情" :visible="lookDialog" width="500px" @close="lookDialog = false">
      <json-viewer
        :value="dataObj"
      ></json-viewer>
    </el-dialog> -->
  </div>
</template>

<script>
import mixin from "@/mixins/mixin";
import detailDrawer from "./detailDrawer.vue";

// import {getUserInfo} from '@/utils/public'
export default {
  mixins: [mixin],
  name: "orderCenter",
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/api/merchant/orderCenter/searchByPage",
        createdIsNeed: false,
      },
      commandForm: {
        status: "",
        orderType: "",
      },
      dataList: [],
      drawer: false,
      activeKey: "1", //切换tab
      detailsInfo: {},

      // lookDialog: false,
      // dataObj: {},
      tradeList: [
        // { id: 1, label: "所有", value: "" },
        // {
        //   id: 2,
        //   label: "服务购买-融聚交易标准版",
        //   value: "meal_charge_standard",
        // },
        // {
        //   id: 3,
        //   label: "服务购买-融聚交易专业版",
        //   value: "meal_charge_speciality",
        // },
        // {
        //   id: 4,
        //   label: "服务购买-融聚交易旗舰版",
        //   value: "meal_charge_flagship",
        // },
        // { id: 5, label: "服务购买-多级商户", value: "meal_charge_merchant" },
        // { id: 6, label: "服务购买-用户账户", value: "meal_charge_account" },
        // { id: 7, label: "充值", value: "recharge" },
        // { id: 8, label: "套餐超量", value: "meal_excess" },
        // { id: 9, label: "服务升级", value: "meal_upgrade" },
        // { id: 10, label: "定制套餐升级", value: "custom_meal_upgrade" },
      ],
      payStateList: [
        // 交易状态
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "支付超时", value: "expire_pay" },
        { id: 3, label: "待支付", value: "wait_pay" },
        { id: 4, label: "支付成功", value: "success_pay" },
        { id: 5, label: "支付失败", value: "fail_pay" },
        { id: 6, label: "已取消", value: "cancel_pay" },
      ],
    };
  },
  components: {
    detailDrawer,
  },
  created() {
    this.dataForm = JSON.parse(JSON.stringify(this.commandForm));
    this.getDataList();
    this.getSeleList();
    // this.getServiceProduct();
    // console.log(getUserInfo());
  },
  methods: {
    getSeleList() {
      this.$http.get("/api/merchant/orderCenter/getServiceList").then((res) => {
        if (res.code === "0000") {
          this.tradeList = res.data;
          this.tradeList.unshift({ orderType: "", orderTypeName: "所有" });
        }
      });
    },
    linkToPayCenter(url) {
      window.open(url);
    },
    NoPay(row) {
      this.$http
            .post(`/api/merchant/orderCenter/cancel`,{id:row.id})
            .then((res) => {
              if (res.code === "0000") {
    this.getDataList();
          this.$message.success('取消订单成功！')
              }
            });
    },
    handleDetails(row) {
      switch (this.activeKey) {
        case "1":
          this.$http
            .get(`/api/merchant/orderCenter/getById?id=${row.id}`)
            .then((res) => {
              if (res.code === "0000") {
                this.detailsInfo = res.data;
                this.drawer = true;
              }
            });
          break;
        default:
          break;
      }
    },
    getServiceProduct() {
      this.$http.get("/sys/meal/listMeal").then((res) => {
        if (res.code === "0000") {
          this.mealList = res.data;
          this.mealList.unshift({ id: "", serviceName: "所有" });
        }
      });
    },
    // handleClick(row) {
    //   this.lookDialog = true
    //   this.dataObj = row
    // },
    setMealType(val) {
      let str = "";
      switch (val) {
        case "charge":
          str = "融聚交易";
          break;
        case "account":
          str = "会员账户";
          break;
        case "merchant":
          str = "多级商户";
          break;
        case "base":
          str = "基础套餐";
          break;
      }
      return str;
    },
    setPayStatus(val) {
      let str = "";
      switch (val) {
        case "expire_pay":
          str = "支付超时";
          break;
        case "wait_pay":
          str = "待支付";
          break;
        case "success_pay":
          str = "支付成功";
          break;
        case "fail_pay":
          str = "支付失败";
          break;
        case "cancel_pay":
          str = "已取消";
          break;
      }
      return str;
    },
  },
};
</script>

<style scoped lang="scss">
.failed {
  color: #f42b2b;
}
.succeed {
  color: #07a555;
}
.pedding {
  color: #f69c1f;
}
:deep(.el-form-item) {
  margin-bottom: 0;
}
:deep(.jv-code) {
  padding: 0;
}
</style>
